home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / wftp.zip / sample / main2.c < prev   
C/C++ Source or Header  |  1994-10-20  |  6KB  |  260 lines

  1.  
  2. /* **************************************************************
  3.  *
  4.  *
  5.  *      C W   :    P r o c Θ d u r e s
  6.  * 
  7.  *
  8.  * **************************************************************** */
  9.  
  10.  
  11. #include <windows.h>
  12.  
  13. #include "wftp.h"
  14.  
  15. int Ecris(const char *szFormat,...);
  16.  
  17.  
  18. /* **************************************************************
  19.  *    I n d i c a t e u r    D ' a v a n c e m e n t 
  20.  *             P a r    Santanu Lahiri (winFTP)
  21.  * **************************************************************/
  22.  
  23.  
  24. extern HINSTANCE       hInst;             
  25. static bRecv = FALSE;
  26. static DWORD lFileSize=0;
  27. static LONG lTotalBytes=0, lXferBytes=0;
  28. static int  nPercentXfer;
  29. static HWND hWndXfer=NULL;
  30. static LPSTR szXferWnd = "XferWindow";
  31.  
  32.  
  33. HPEN hPenDark;
  34. HPEN hPenLight;
  35. HBRUSH  hbrGray1;
  36. int  nWndx=10;                // the x axis multiplier
  37. int  nWndy=15;                // the y axis multiplier
  38.  
  39. LRESULT CALLBACK WndXferProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
  40.  
  41.  
  42. int nCwUnregisterClasses(void)
  43. {
  44.   UnregisterClass (szXferWnd, hInst);
  45. return 0;
  46. }
  47.  
  48.  
  49. int nCwRegisterClasses(void)
  50. {
  51. WNDCLASS   wc;    // struct to define a window class
  52.  
  53.   hbrGray1 = CreateSolidBrush (RGB (192,192,192));
  54.   memset(&wc, 0x00, sizeof(wc));
  55.   wc.cbClsExtra = 0;
  56.   wc.cbWndExtra = 0;
  57.   wc.hInstance = hInst;
  58.   wc.hCursor = LoadCursor ((HINSTANCE) NULL, IDC_ARROW);
  59.   wc.style = CS_HREDRAW | CS_VREDRAW;
  60.   wc.lpfnWndProc   = WndXferProc;
  61.   wc.hIcon         = LoadIcon (hInst, IDI_APPLICATION);
  62.   wc.hbrBackground = hbrGray1;
  63.   wc.lpszMenuName  = NULL;      /* Menu Name is App Name */
  64.   wc.lpszClassName = szXferWnd; /* Class Name is App Name */
  65.   if (RegisterClass (&wc)==0) return -1;
  66. return 0;
  67. }
  68.  
  69.  
  70. void CreateButtonPens()
  71. {
  72.   hPenDark  = CreatePen (PS_SOLID, 1, RGB (128,128,128));
  73.   hPenLight = CreatePen (PS_SOLID, 1, RGB (224,224,224));
  74. }
  75.  
  76. void DeleteButtonPens()
  77. {
  78.   DeleteObject (hPenDark);
  79.   DeleteObject (hPenLight);
  80. }
  81.  
  82.  
  83. void BoxIt (HDC hDC, int left, int top, int width, int height, BOOL flag)
  84. {
  85.   POINT Pt;
  86.   HPEN hPenOld;
  87.   
  88.   hPenOld = SelectObject (hDC, flag? hPenDark : hPenLight);
  89.   MoveToEx (hDC, (left*nWndx)/4, ((top+height)*nWndy)/8, &Pt);
  90.   LineTo (hDC, (left*nWndx)/4, (top*nWndy)/8);
  91.   LineTo (hDC, ((left+width)*nWndx)/4, (top*nWndy)/8);
  92.   if (flag) SelectObject (hDC,hPenLight); 
  93.   else SelectObject (hDC,hPenDark);
  94.   LineTo (hDC, ((left+width)*nWndx)/4, ((top+height)*nWndy)/8);
  95.   LineTo (hDC, (left*nWndx)/4, ((top+height)*nWndy)/8);
  96.   SelectObject (hDC, hPenOld);
  97. }
  98.  
  99.  
  100. void PaintXfer (HDC hDC)
  101. {
  102.   RECT rc;
  103.   char szBuf[10];
  104.  
  105.   CreateButtonPens();
  106.   SelectObject (hDC, GetStockObject (WHITE_BRUSH));
  107.   Rectangle (hDC, (nWndx*20)/4, (nWndy*10)/8, (nWndx*122)/4, (nWndy*20)/8);
  108.   rc.left = (nWndx*21)/4;  rc.right = (nWndx*(nPercentXfer+21))/4;
  109.   rc.top  = (nWndy*11)/8;  rc.bottom= (nWndy*19)/8;
  110.   FillRect (hDC, &rc, GetStockObject (GRAY_BRUSH));
  111.   rc.right = (nWndx*121)/4;
  112.   SetBkMode (hDC, TRANSPARENT);
  113.   wsprintf (szBuf, "%d%%", nPercentXfer);
  114.   DrawText (hDC, szBuf, lstrlen (szBuf), &rc, DT_CENTER | DT_VCENTER);
  115.   SetBkMode (hDC, OPAQUE);
  116.   BoxIt (hDC, 18, 8, 106, 14, FALSE);
  117.   DeleteButtonPens();
  118. }
  119.  
  120.  
  121.  
  122. void OnPaintXfer (HWND hWnd)
  123. {
  124.   HDC hDC;
  125.   PAINTSTRUCT ps;
  126.   
  127.   hDC = BeginPaint (hWnd, &ps);
  128.   PaintXfer (hDC);
  129.   EndPaint (hWnd, &ps);
  130. }
  131.  
  132. void SetXmitBytes (LONG lBytes)
  133. {
  134.   int nOld;
  135.   
  136.   lXferBytes = lBytes;
  137.   if ((lTotalBytes==0)||(hWndXfer==NULL)) return;
  138.   nOld = nPercentXfer;
  139.   nPercentXfer = (int) ((lBytes*100)/lTotalBytes);
  140.   if (nOld!=nPercentXfer) 
  141.   {
  142.     HDC hDC;
  143.   
  144.     hDC = GetDC (hWndXfer);
  145.     PaintXfer (hDC);
  146.     ReleaseDC (hWndXfer, hDC);
  147.   }
  148. }
  149.  
  150.  
  151.  
  152. LRESULT CALLBACK WndXferProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  153. {
  154.   switch (Msg)
  155.   {
  156.     case WM_GETMINMAXINFO: 
  157.     {
  158.       MINMAXINFO FAR *lpmmi=(MINMAXINFO FAR *) lParam;
  159.       lpmmi->ptMaxSize.x = (nWndx*140)/4;
  160.       lpmmi->ptMaxSize.y = (nWndy*45)/8;
  161.       lpmmi->ptMaxTrackSize.x = (nWndx*140)/4;
  162.       lpmmi->ptMaxTrackSize.y = (nWndy*45)/8;
  163.       lpmmi->ptMinTrackSize.x = (nWndx*140)/4;
  164.       lpmmi->ptMinTrackSize.y = (nWndy*45)/8;
  165.     } break;
  166.     case WM_PAINT: OnPaintXfer (hWnd); return 0L;
  167.   }
  168.   return (LRESULT) DefWindowProc (hWnd, Msg, wParam, lParam);
  169. }
  170.  
  171. void CreateXferWindow()
  172. {
  173.   if (hWndXfer!=NULL) return;
  174.   hWndXfer = CreateWindowEx ( WS_EX_TOPMOST, 
  175.        szXferWnd, "",  WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CAPTION,
  176.        CW_USEDEFAULT, CW_USEDEFAULT, (nWndx*140)/4, (nWndy*40)/8, (HWND) NULL, 
  177.        (HMENU) NULL, hInst,  NULL);
  178.   if (hWndXfer==NULL) MessageBeep (65535u);
  179.   lTotalBytes = 0L;
  180.   lXferBytes  = 0L;
  181.   nPercentXfer = 0L;
  182. }
  183.  
  184.  
  185. void DeleteXferWindow()
  186. {
  187.   if (hWndXfer==NULL) return;
  188.   DestroyWindow (hWndXfer);
  189.   lTotalBytes  = lXferBytes = 0l;
  190.   nPercentXfer = 0;
  191.   hWndXfer = NULL;
  192. }
  193.  
  194. void SetXferWindowText (LPSTR lpStr)
  195. {
  196.   SetWindowText (hWndXfer, lpStr);
  197. }
  198.  
  199.  
  200. /* **************************************************************
  201.  *    P r o c Θ d u r e s    
  202.  * **************************************************************/
  203.  
  204.  
  205. int PASCAL FAR  DLL_Work (HWND hParent, UINT Msg)
  206. {
  207.     FtpInit (hParent);
  208.     FtpSetVerboseMode (TRUE, hParent, WM_USER+112);
  209.     FtpLogin (HOST, USERID, PASSWD, hParent, Msg);
  210. return 0;
  211. }
  212.  
  213.  
  214. int PASCAL FAR  DLL_Dir (HWND hParent, BOOL First, UINT Msg)
  215.    if (First)
  216.     {
  217.        FtpCWD (".");
  218.        FtpDir ("/tmp/dir/l*", "\\Z", TRUE, hParent, Msg);
  219.     }
  220.    else 
  221.     {
  222.        FtpCWD ("/");
  223.        FtpDir ("", NULL, FALSE, hParent, Msg);
  224.     }
  225. return 0;
  226. }
  227.  
  228. int PASCAL FAR  DLL_FT (HWND hParent, BOOL First, UINT Msg)
  229.    if (First)
  230.      { 
  231.        bRecv = TRUE;
  232.        FtpRecvFile ("/tmp/big.txt", "\\tmp\\big.txt", TYPE_I, TRUE, hParent, Msg);
  233.      }
  234.    else
  235.        FtpSendFile ("\\tmp\\ftp.lst", "/users/Ark/tmp/ftp.lst", TYPE_A, FALSE, hParent, Msg);
  236.  
  237.    Ecris (First ? "RΘception  big.txt" : "Envoi  ftp.lst");
  238.    if (bRecv)
  239.      {
  240.        lFileSize = FtpGetFileSize ();
  241.        if (lFileSize!=0) Ecris ("Taille fichier %ld", lFileSize);
  242.        CreateXferWindow ();
  243.        SetXferWindowText ("/tmp/big.txt");
  244.        lTotalBytes = lFileSize;
  245.        Ecris ("Reponse : [%s]", FtpDataPtr ()->ftp.szInBuf);
  246.      }
  247. return 0;
  248.  
  249.  
  250. int PASCAL FAR  DLL_End ()
  251. {
  252.     FtpCloseConnection ();
  253.     FtpRelease ();
  254. return 0;
  255. }
  256.  
  257.